package com.spsoft.vatoutinv.controller;

import com.spsoft.core.annotation.AnonymousAccess;
import com.spsoft.core.annotation.Log;
import com.spsoft.core.enums.LogActionType;
import com.spsoft.core.enums.LogMenuEnum;
import com.spsoft.vatoutinv.service.commoninvoice.CommonInvoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 公共前端控制器
 *
 * @author chenxudong
 * @since 2024-06-13
 */
@Api(tags = {"公共控制层"})
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/common")
public class VmsCommonController {

    public static final String LOG_MSG = "(公共控制层)";

    private final CommonInvoiceService commonInvoiceService;

    @ApiOperation("下载Excel导入模板")
    @AnonymousAccess(value = "/downloadExcel", method = RequestMethod.GET, permissionCode = "")
    @Log(value = "下载Excel导入模板", type = LogActionType.DOWNLOAD, menuName = LogMenuEnum.COMMON)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "excelType", value = "Excel模板种类代码", dataTypeClass = String.class, dataType = "String", required = true)
    })
    public void downloadExcel(@RequestParam(value = "excelType") String excelType, HttpServletResponse response) {
        log.info("{}下载Excel导入模板，excelType：{}", LOG_MSG, excelType);
        commonInvoiceService.downloadExcel(excelType, response);
    }
}
